<?php
class Managearticles_Data_Addedaction {
	
	private $database;
	private $secure;
	
	public function __construct(){
		$this->database = new Core_Driver_MysqlImproved();
		$this->secure = new Core_Data_Secure();	
	}
	
	public function addValues($postVars){
		
		$postVars = $this->secure->parseData($postVars);
		
		$category = $postVars['category'];
		$pageName = $postVars['pageName'];
		$pageMetaTitle = $postVars['pageMetaTitle'];
		$pageKeywords = $postVars['pageKeywords'];
		$pageMetaDescription = $postVars['pageMetaDescription'];
		$pageTitle = $postVars['pageTitle'];
		$pageDescription = $postVars['pageDescription'];
		$pageContent = $postVars['pageContent'];
		$pageAccessLevel = $postVars['accessLevel'];
		$available = $postVars['available'];
		$this->addPageSettingsValues($pageName, $pageAccessLevel, $available, $category);
		
		$this->addPageMetaValues($pageName, $pageMetaTitle, $pageMetaDescription, $pageKeywords);
		
		$this->addPageContentValues($pageName, $pageTitle, $pageDescription, $pageContent);
		
		echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?managearticles">';
	}
	
	private function addPageSettingsValues($pageName, $pageAccessLevel, $available, $category){
		$this->database->connect();
		$category = $this->database->escape($category);
		$pageName = $this->database->escape($pageName);
		$pageAccessLevel = $this->database->escape($pageAccessLevel);
		$available = $this->database->escape($available);
		$this->database->prepare("
				insert into page_settings(page_name, page_access_level, page_active, page_category) values('$pageName', '$pageAccessLevel', '$available', '$category');
				");
		$this->database->query();
		$this->database->dataOperations();
	}
	
	private function addPageMetaValues($pageName, $pageMetaTitle, $pageMetaDescription, $pageKeywords){
		$this->database->connect();
		$pageName = $this->database->escape($pageName);
		$pageMetaTitle = $this->database->escape($pageMetaTitle);
		$pageMetaDescription = $this->database->escape($pageMetaDescription);
		$pageKeywords = $this->database->escape($pageKeywords);
		$this->database->prepare(
			"insert into page_meta_values(page_name, page_meta_title, page_meta_description, page_meta_keywords) values('$pageName', '$pageMetaTitle', '$pageMetaDescription', '$pageKeywords');"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
	
	private function addPageContentValues($pageName, $pageTitle, $pageDescription, $pageContent){
		$this->database->connect();
		$pageName = $this->database->escape($pageName);
		$pageTitle = $this->database->escape($pageTitle);
		$pageDescription = $this->database->escape($pageDescription);
		$pageContent = $this->database->escape($pageContent);
		$this->database->prepare(
			"
				insert into page_content_values(page_name, page_title, page_description, page_content) values('$pageName', '$pageTitle', '$pageDescription', '$pageContent');
				"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
}